<script setup>
// 同步省市信息 数据库 ==》 redis
import uu from "@/util/uu";
import {ElMessage} from "element-plus";
import {reactive} from "vue";
let data = reactive({ // 数据区域
  redisKey:"", // redis里的键
  dialogVisible:false, // 对话框状态
})

const area = () => {
  console.log("开始发送同步信息请求")
  uu.get("/hupRegion/synchronizationArea").then(result =>{
    if (result.code == 200){
      ElMessage({
        message: '同步信息成功',
        type: 'success',
      })
    }else if (result.code == 500){
      ElMessage.error(result.message)
    }
  })
}
const getAreaMessgae = () => {
  uu.get("/hupRegion/getAreaForRedis/"+data.redisKey).then(result =>{
    if (result.code === 200){
      ElMessage({
        message: '信息查询成功',
        type: 'success',
      })
      alert(JSON.stringify(result.data))
      console.log("!!!!!!!!!!!!!!!!")
      console.log("!!!!!!!!!!!!"+JSON.stringify(result.data))
    }else if (result.code === 500){
      ElMessage.error(result.message)
    }
  })
}
</script>

<template>
  <el-button type="success" @click="area()">同步省市信息</el-button>

  <el-dialog
      v-model="data.dialogVisible"
      title="查询redis数据"
      width="30%"
      :before-close="handleClose"
  >
    <span>This is a message</span>
    <el-form>
      <el-form-item>
        <el-input type="text" placeholder="请输入键值" v-model="data.redisKey"/>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="data.dialogVisible = false">Cancel</el-button>
        <el-button type="primary" @click="getAreaMessgae()">
          Confirm
        </el-button>
      </span>
    </template>
  </el-dialog>

  <el-button type="success" @click="data.dialogVisible = true">获取省市信息</el-button>
</template>

<style scoped>

</style>